﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Livraria._Default" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<script language = "c#" runat ="server">
    SqlConnection conn;
    
    public void Page_Load(Object src, EventArgs E)
    {
        string strConnectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=LinguagemWeb;Integrated Security=True";
        conn = new SqlConnection(strConnectionString);
        
        if(!IsPostBack)
        {
            BindDG();
        }
    }
    private void BindDG()
    {
        String sqlQuery = "Select * from Produtos";
        SqlDataAdapter command = new SqlDataAdapter(sqlQuery, conn);
          
        DataSet ds = new DataSet ();
        command.Fill (ds, "Produtos");
        
        dgLivraria.DataSource = ds.Tables["Produtos"];
        dgLivraria.DataBind();
    }

</script>
<head runat="server">
    <title>Livraria</title>
</head>
<body>
    <form id="livraria" runat="server">
    <h3>
        Livraria do Mario
    </h3>
    <span id="Message" enableviewstate="false" runat="server" />
    <asp:DataGrid ID="dgLivraria" Width="400" runat="server" ShowFooter="false">
        <Columns>
            <asp:EditCommandColumn EditText="Editar" UpdateText="Atualizar" CancelText="Cancelar" />
        </Columns>
    </asp:DataGrid>
    </form>
</body>
</html>
